﻿#region Copyright 
/*-------------------------------------------------------------------------
* 命名空间名称/文件名:    SSPivot.Authorization/GlobalConfig 
* CLR版本:     4.0.30319.42000
* 机器名称:    DESKTOP-NHMLO8A
* 功 能：       N/A
* 类 名：       GlobalConfig
* 创建时间：  2025/5/24 11:05:06
* 版本号：      v1.0
* 创建人:        xulong
*-------------------------------------------------------------------------*/
#endregion
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SSPivot.Authorization
{
    /// <summary>
    /// 系统配置
    /// </summary>
    public class GlobalConfigAuth:GlobalConfigCommon
    {
        public const string AuthorizationHeader="Authorization";
        public const string AuthenticationScheme = "Authorization";
        public const string AuthorizationPolicy = "PermissionCheck";

        public class CacheKeys
        {

            /// <summary>
            /// 用户权限 admin:user:permissions:userId
            /// </summary>
            [Description("用户权限")]
            public const string UserPermission = "admin:user:permission:";

            /// <summary>
            /// 数据权限 admin:user:data:permission:userId
            /// </summary>
            [Description("数据权限")]
            public const string DataPermission = "admin:user:data:permission:";

            /// <summary>
            /// 获取数据权限缓存键
            /// </summary>
            /// <param name="userId">用户Id</param>
            /// <param name="apiPath">请求接口路径</param>
            /// <returns></returns>
            public static string GetDataPermissionKey(long userId, string apiPath = null)
            {
                if (apiPath.IsNull())
                {
                    //apiPath = AppInfo.CurrentDataPermissionApiPath;
                }

                return $"{DataPermission}{userId}{(apiPath.IsNotNullOrEmpty() ? (":" + apiPath) : "")}";
            }

            /// <summary>
            /// 获取数据权限缓存键
            /// </summary>
            /// <param name="userId">用户Id</param>
            /// <returns></returns>
            public static string GetUserPermissionKey(long userId) => $"{UserPermission}{userId}";

            /// <summary>
            /// 获取数据权限模板
            /// </summary>
            /// <param name="userId">用户Id</param>
            /// <returns></returns>
            public static string GetDataPermissionPattern(long userId) => $"{DataPermission}{userId}*";
        }
    }
}
